package com.huawei.chengdu.meetingdemo.presenter;

import android.content.Context;
import android.text.TextUtils;

import com.device.idea.meeting.Account.model.H323ServerInfo;
import com.device.idea.meeting.Account.model.H323ServerInfoBase;
import com.device.idea.meeting.Account.model.SIPServerInfo;
import com.device.idea.meeting.Account.model.SIPServerInfoBase;
import com.device.idea.meeting.Addressbook.model.AddrBookNetUserInfo;
import com.device.idea.meeting.Addressbook.model.AddrBookProtocol;
import com.device.idea.meeting.Addressbook.model.AddrBookUserInfo;
import com.device.idea.meeting.AppInfo;
import com.device.idea.meeting.CallCtrl.model.CallParam;
import com.device.idea.meeting.CallCtrl.model.CallProtocol;
import com.device.idea.meeting.CallCtrl.model.CallStatus;
import com.device.idea.meeting.CallCtrl.model.ConfParam;
import com.device.idea.meeting.CallRecord.model.CallRecordInfo;
import com.device.idea.meeting.CallRecord.model.CallRecordType;
import com.device.idea.meeting.ConfCtrl.model.AttendeeInfo;
import com.device.idea.meeting.ConfCtrl.model.ParticipantInfo;
import com.device.idea.meeting.ConfCtrl.model.TermCtrlSiteInfo;
import com.device.idea.meeting.ConfCtrl.model.TermSwitchInfo;
import com.device.idea.meeting.ConfManage.model.ConfInfo;
import com.device.idea.meeting.FlexibleLayout.model.VideoLocalView;
import com.device.idea.meeting.FlexibleLayout.model.VideoRemoteViewAndUser;
import com.device.idea.meeting.IMeetingControlEventHandler;
import com.device.idea.meeting.MeetingCallback;
import com.device.idea.meeting.MeetingServiceController;
import com.device.idea.meeting.MultiStream.model.LayoutMode;
import com.device.idea.meeting.MultiStream.model.StreamType;
import com.device.idea.meeting.MultiStream.model.SurfaceViewInfo;
import com.device.idea.meeting.Share.model.ShareAbleInfo;
import com.device.idea.meeting.Share.model.ShareCurInfo;
import com.device.idea.meeting.Share.model.ShareStartInfo;
import com.huawei.chengdu.meetingdemo.consts.ConfConst;
import com.huawei.chengdu.meetingdemo.util.LogUtil;
import com.huawei.chengdu.meetingdemo.view.HomeActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * SDK接口调用类
 *
 * @author L00354002
 * @since 2022-8-30
 */
public class ConfSdkPresenter {
    private static final String TAG = ConfSdkPresenter.class.getSimpleName();
    private static MeetingServiceController meetingServiceController;
    private static HomeActivity uiInstance;
    //会场号
    private static String hostName = "";

    public static void setUiInstance(HomeActivity homeActivity) {
        uiInstance = homeActivity;
    }

    /**
     * 初始化SDK
     *
     * @param handler 回调处理handler
     * @return
     */
    public static void initSdkController(Context context, AppInfo appInfo, IMeetingControlEventHandler handler) {
        if (meetingServiceController == null) {
            LogUtil.info("Init SDK");
            meetingServiceController = MeetingServiceController.create(context, appInfo, handler);
        }
    }

    /**
     * 去初始化SDK
     *
     * @param context
     */
    public static void destroySdk(Context context) {
        LogUtil.info("Destroy SDK");
        if (meetingServiceController != null) {
            meetingServiceController.destroy(context);
            meetingServiceController = null;
        }
    }

    /**
     * 发起呼叫
     *
     * @param number
     */
    public static void startCall(String number) {
        uiInstance.showStartCallDialog(number);
        CallParam callParam = new CallParam();
        callParam.setRate(ConfConst.DFT_CALL_WIDTH); // 呼叫带宽
        callParam.setProtocol(CallProtocol.AUTO); // 线路类型
        callParam.setVideo(true); // 默认视频会议
        callParam.setCalleeNumber(number); // 号码
        callParam.setDisplayName(number);
        int result = meetingServiceController.callServiceController.startCall(callParam);
        LogUtil.info("Start call num = " + number + " result = " + result);
        if (result != 0) {
            uiInstance.dismissStartCallDialog();
        }
    }

    public static void startCallWithParam(CallParam callParam) {
        uiInstance.showStartCallDialog(callParam.getCalleeNumber());
        int result = meetingServiceController.callServiceController.startCall(callParam);
        LogUtil.info("Start call param = " + callParam + " result = " + result);
    }

    /**
     * 呼叫本地通讯录联系人
     *
     * @param addrBookUserInfo 联系人信息
     */
    public static void addressBookCall(AddrBookUserInfo addrBookUserInfo) {
        String callNum;
        // 获取呼叫号码 号码 > url > ip > 名称
        if (!TextUtils.isEmpty(addrBookUserInfo.getLineInfo().getSiteNumber())) {
            callNum = addrBookUserInfo.getLineInfo().getSiteNumber();
        } else if (!TextUtils.isEmpty(addrBookUserInfo.getLineInfo().getUrl())) {
            callNum = addrBookUserInfo.getLineInfo().getUrl();
        } else if (!TextUtils.isEmpty(addrBookUserInfo.getLineInfo().getIp())) {
            callNum = addrBookUserInfo.getLineInfo().getIp();
        } else {
            callNum = addrBookUserInfo.getName();
        }
        AddrBookProtocol addrBookProtocol = addrBookUserInfo.getLineType();
        CallProtocol callProtocol = addrBookProtocol.ordinal() < 2 ? CallProtocol.getType(addrBookProtocol.ordinal())
                : CallProtocol.AUTO;
        CallParam callParam = new CallParam();
        callParam.setRate(addrBookUserInfo.getLineInfo().getCallRate());
        callParam.setProtocol(callProtocol);
        callParam.setVideo(true);
        callParam.setCalleeNumber(callNum);
        callParam.setDisplayName(addrBookUserInfo.getName());
        startCallWithParam(callParam);
    }

    /**
     * 呼叫网络通讯录联系人
     *
     * @param addrBookNetUserInfo 联系人信息
     */
    public static void companyAddressBookCall(AddrBookNetUserInfo addrBookNetUserInfo) {
        String callNum;
        if (!TextUtils.isEmpty(addrBookNetUserInfo.getLineInfo().getSiteNumber())) {
            callNum = addrBookNetUserInfo.getLineInfo().getSiteNumber();
        } else if (!TextUtils.isEmpty(addrBookNetUserInfo.getLineInfo().getUrl())) {
            callNum = addrBookNetUserInfo.getLineInfo().getUrl();
        } else if (!TextUtils.isEmpty(addrBookNetUserInfo.getLineInfo().getIp())) {
            callNum = addrBookNetUserInfo.getLineInfo().getIp();
        } else {
            LogUtil.error("there is not non-empty number to call");
            return;
        }
        CallParam callParam = new CallParam();
        callParam.setCalleeNumber(callNum);
        callParam.setRate(ConfConst.DFT_CALL_WIDTH);
        callParam.setProtocol(CallProtocol.getType(addrBookNetUserInfo.getLineType().ordinal()));
        callParam.setDisplayName(addrBookNetUserInfo.getName());
        startCallWithParam(callParam);
    }

    /**
     * 呼叫通话记录中的会场
     *
     * @param callRecordInfo 通话记录信息
     */
    public static void callRecordCall(CallRecordInfo callRecordInfo) {
        CallParam callParam = new CallParam();
        callParam.setCalleeNumber(callRecordInfo.getCallNumber());
        callParam.setRate(callRecordInfo.getCallRate());
        callParam.setProtocol(callRecordInfo.getProtocol());
        callParam.setVideo(callRecordInfo.isVideo());
        callParam.setDisplayName(callRecordInfo.getCallName());
        startCallWithParam(callParam);
    }

    /**
     * 取消呼叫
     *
     * @return 0：成功 其他：失败
     */
    public static int cancelCall() {
        int result = meetingServiceController.callServiceController.cancelCall();
        LogUtil.info("Cancel call result = " + result);
        return result;
    }

    /**
     * 拒绝呼叫
     *
     * @return 0：成功 其他：失败
     */
    public static int refuseCall() {
        int result = meetingServiceController.callServiceController.refuseCall();
        LogUtil.info("Refuse call result = " + result);
        return result;
    }

    /**
     * 接受呼叫
     *
     * @return 0：成功 其他：失败
     */
    public static int acceptCall() {
        int result = meetingServiceController.callServiceController.acceptCall();
        LogUtil.info("Accept call result = " + result);
        return result;
    }

    /**
     * 创建会议
     *
     * @param confInfo 会议信息
     */
    public static void createConf(ConfInfo confInfo) {
        uiInstance.showStartCallDialog(confInfo.getName());
        meetingServiceController.confManagerServiceController.createConference(confInfo, new MeetingCallback<Integer>() {
            @Override
            public void onSuccess(Integer result) {
                LogUtil.info("Create conf success, conf = " + confInfo.getName());
            }

            @Override
            public void onFailed(int errCode, String err) {
                LogUtil.error("Create conf fail, conf = " + confInfo.getName() + " errCode = " + errCode + " err = " + err);
                uiInstance.dismissStartCallDialog();
            }
        });
    }

    /**
     * 获取SIP账号信息
     *
     * @return
     */
    public static SIPServerInfoBase getSIPAccountInfo() {
        return meetingServiceController.accountInfoController.getSIPAccountInfo();
    }

    /**
     * 获取H323账号信息
     *
     * @return
     */
    public static H323ServerInfoBase getH323AccountInfo() {
        return meetingServiceController.accountInfoController.getH323AccountInfo();
    }

    /**
     * 设置SIP账号信息
     *
     * @param sipServerInfo
     * @return
     */
    public static int setSIPAccountInfo(SIPServerInfo sipServerInfo) {
        int result = meetingServiceController.accountInfoController.setSIPAccountInfo(sipServerInfo);
        LogUtil.info("Set SIP account result = " + result);
        return result;
    }

    /**
     * 设置H323账号信息
     *
     * @param h323ServerInfo
     * @return
     */
    public static int setH323AccountInfo(H323ServerInfo h323ServerInfo) {
        int result = meetingServiceController.accountInfoController.setH323AccountInfo(h323ServerInfo);
        LogUtil.info("Set H323 account result = " + result);
        return result;
    }

    public static int getCallRecord() {
        int result = meetingServiceController.callRecordServiceController.getCallRecord();
        LogUtil.info("Search call record result = " + result);
        return result;
    }

    public static int deleteCallRecord(int callRecordId, CallRecordType callRecordType) {
        int result = meetingServiceController.callRecordServiceController.deleteSingleCallRecord(callRecordId, callRecordType);
        return result;
    }

    public static int clearCallRecord() {
        int result = meetingServiceController.callRecordServiceController.resetCallRecord();
        return result;
    }

    public static int searchConfList() {
        int result = meetingServiceController.confManagerServiceController.getBookConfList(null);
        LogUtil.info("Search conf list result = " + result);
        return result;
    }

    public static int leaveConf() {
        if (meetingServiceController == null) {
            LogUtil.error("meetingServiceController is null");
            return -1;
        }
        int result = meetingServiceController.callServiceController.endCall();
        LogUtil.info("Leave conf result = " + result);
        return result;
    }

    public static int endConf() {
        int result = meetingServiceController.confCtrlServiceController.endConference(new MeetingCallback() {
            @Override
            public void onSuccess(Object o) {
                LogUtil.info("end conf success!");
            }

            @Override
            public void onFailed(int errCode, String errMsg) {
                LogUtil.error("End conf fail, errCode = " + errCode + " errMsg = " + errMsg);
            }
        });
        LogUtil.info("End conf result = " + result);
        return result;
    }

    public static int searchAllLocalUsers(MeetingCallback<List<AddrBookUserInfo>> callback) {
        int result = meetingServiceController.addressBookService.searchAllUsers(callback);
        LogUtil.info("Search local user result = " + result);
        return result;
    }

    public static int deleteLocalUser(int id) {
        int result = meetingServiceController.addressBookService.deleteUserById(id);
        return result;
    }

    public static int modifyLocalUser(int id, AddrBookUserInfo userInfo) {
        int result = meetingServiceController.addressBookService.modifyUserById(id, userInfo);
        LogUtil.info("modify local user result = " + result);
        return result;
    }

    public static int addLocalUser(AddrBookUserInfo addrBookUserInfo) {
        int result = meetingServiceController.addressBookService.addUser(addrBookUserInfo);
        return result;
    }

    public static int searchCompanyUsers(String keyWord, MeetingCallback<List<AddrBookNetUserInfo>> callback) {
        int result = meetingServiceController.addressBookService.searchNetAddressBookInfo(keyWord, callback);
        LogUtil.info("Search net user by keyword result = " + result);
        return result;
    }

    public static int searchLocalUserByKeyword(String keyword, MeetingCallback<List<AddrBookUserInfo>> callback) {
        int result = meetingServiceController.addressBookService.searchUserByKeyWord(keyword, callback);
        LogUtil.info("Search local user by keyword result = " + result);
        return result;
    }

    /**
     * 申请主席
     *
     * @param code 主席密码
     */
    public static int applyChairmanAuthority(String code, MeetingCallback meetingCallback) {
        int result = meetingServiceController.confCtrlServiceController.applyChairmanAuthority(code, meetingCallback);
        LogUtil.info("A user has tried to apply the chairman right" + result);
        return result;
    }

    /**
     * 释放主席
     */
    public static int releaseChairmanAuthority(MeetingCallback meetingCallback) {
        int result = meetingServiceController.confCtrlServiceController.releaseChairmanAuthority(meetingCallback);
        LogUtil.info("A user has released the chairman right" + result);
        return result;
    }

    /**
     * 开启本地摄像头
     *
     * @return
     */
    public static int openCamera() {
        int result = meetingServiceController.openCamera();
        LogUtil.info("Open Camera result = " + result);
        return result;
    }

    /**
     * 关闭本地摄像头
     *
     * @return
     */
    public static int closeCamera() {
        int result = meetingServiceController.closeCamera();
        LogUtil.info("Close Camera result = " + result);
        return result;
    }

    /**
     * 获取摄像头状态
     *
     * @return
     */
    public static boolean isCameraOpen() {
        boolean cameraOpen = meetingServiceController.isCameraOpen();
        LogUtil.info(" Camera states = " + cameraOpen);
        return cameraOpen;
    }

    /**
     * 窗口view创建成功通知
     *
     * @param viewList
     */
    public static void confirmViewCreateSuccess(List<SurfaceViewInfo> viewList) {
        viewList.get(viewList.size() - 1).getSurfaceView().post(() -> {
            int result = meetingServiceController.layoutController.confirmViewCreateSuccess(viewList);
            LogUtil.info("Bind viewId and surfaceView result = " + result);
        });
    }

    /**
     * 获取麦克风状态
     */
    public static boolean isMicrophoneOpen() {
        boolean microphoneOpen = meetingServiceController.isMicrophoneOpen();
        LogUtil.info("Meeting Get Mic State=" + microphoneOpen);
        return microphoneOpen;
    }

    /**
     * 打开麦克风
     *
     * @return 返回值
     */
    public static int openMicrophone() {
        int result = meetingServiceController.openMicrophone();
        LogUtil.info("open Microphone=" + result);
        return result;
    }

    /**
     * 关闭麦克风
     *
     * @return 返回值
     */
    public static int closeMicrophone() {
        int result = meetingServiceController.closeMicrophone();
        LogUtil.info("close Microphone=" + result);
        return result;
    }

    /**
     * 二次拨号
     */
    public static int secondCall(char num) {
        int result = meetingServiceController.callServiceController.sendDtmf(num);
        LogUtil.info("second call num " + num + " result = " + result);
        return result;
    }

    /**
     * 是否主席
     */
    public static boolean isChairman() {
        boolean isChairman = meetingServiceController.confCtrlServiceController.getSwitchInfo().isMeIsChair();
        LogUtil.info("Me is chairman = " + isChairman);
        return isChairman;
    }

    /**
     * 打开扬声器
     *
     * @return 返回值
     */
    public static int openSpeaker() {
        int result = meetingServiceController.openSpeaker();
        LogUtil.info("openSpeaker result = " + result);
        return result;
    }

    /**
     * 关闭扬声器
     *
     * @return 返回值
     */
    public static int closeSpeaker() {
        int result = meetingServiceController.closeSpeaker();
        LogUtil.info("closeSpeaker result = " + result);
        return result;
    }

    /**
     * 扬声器是否关闭
     *
     * @return true 闭音 false 开启扬声器
     */
    public static boolean isQuiet() {
        boolean result = !(meetingServiceController.isSpeakerOpen());
        LogUtil.info("isQuiet() isQuiet:" + result);
        return result;
    }

    /**
     * 获取音量
     *
     * @return 音量值
     */
    public static int getAudioVolume() {
        int result = meetingServiceController.getSpeakerVolume();
        LogUtil.info("getAudioVolume volumeInt:" + result);
        return result;
    }

    /**
     * 设置音量
     *
     * @param volume 音量值, 范围是（0 ~ 15 共15个数）
     */
    public static void setAudioVolume(int volume) {
        LogUtil.info("setAudioVolume() volume:" + volume);
        meetingServiceController.setSpeakerVolume(volume);
    }

    /**
     * 其他会场是否存在主席
     *
     * @return true 存在
     */
    public static boolean isHasChairman() {
        LogUtil.info("isHasChairman()");
        if (meetingServiceController == null) {
            LogUtil.info("isHasChairman(), meetingServiceController == null, so return false");
            return false;
        }
        if (meetingServiceController.confCtrlServiceController == null) {
            LogUtil.info("isHasChairman(), confCtrlServiceController = null, so return false");
            return false;
        }
        TermSwitchInfo switchInfo = meetingServiceController.confCtrlServiceController.getSwitchInfo();
        if (switchInfo == null) {
            LogUtil.info("isHasChairman(), switchInfo = null, so return false");
            return false;
        }
        boolean isHasChairman = switchInfo.isHasChair();
        LogUtil.info("isHasChairman:" + isHasChairman);
        return isHasChairman;
    }

    /**
     * 查询与会者列表
     *
     * @return 与会者列表
     */
    public static List<ParticipantInfo> getParticipantList() {
        if (meetingServiceController == null) {
            return null;
        }
        List<ParticipantInfo> attendeeInfos = meetingServiceController.confCtrlServiceController.getAttendeeInfo();
        if (attendeeInfos == null) {
            attendeeInfos = new ArrayList<>();
        }
        LogUtil.info("getParticipantList ,  attendeeInfos.size " + attendeeInfos.size());
        for (ParticipantInfo participantInfo : attendeeInfos) {
            if (participantInfo.isChair()) {
                hostName = participantInfo.getSiteName();
            }
        }
        return attendeeInfos;
    }

    /**
     * 主席会场名称
     *
     * @return hostName
     */
    public static String getHostName() {
        getParticipantList();
        return hostName;
    }

    /**
     * 是否支持发送辅流
     */
    public static boolean isSupportSendShare() {
        boolean isSupport = meetingServiceController.shareServiceController.isSupportSendShare();
        LogUtil.info("Is support share = " + isSupport);
        return isSupport;
    }

    /**
     * 查询可共享列表
     */
    public static ShareAbleInfo getShareList() {
        return meetingServiceController.shareServiceController.getShareList();
    }

    /**
     * 开始共享
     */
    public static int startShare(ShareStartInfo requestInfo, MeetingCallback<Integer> callback) {
        int result = meetingServiceController.shareServiceController.startShare(requestInfo, callback);
        LogUtil.info("Start share result = " + result);
        return result;
    }

    /**
     * 停止共享
     */
    public static int stopShare(MeetingCallback<Integer> callback) {
        int result = meetingServiceController.shareServiceController.stopShare(callback);
        LogUtil.info("Stop share result = " + result);
        return result;
    }

    /**
     * 会议信息
     *
     * @return CallStatus 会议信息
     */
    public static CallStatus getCallStatus() {
        if (meetingServiceController == null) {
            LogUtil.error("meetingServiceController is null");
            return null;
        }
        return meetingServiceController.callServiceController.getCallStatus();
    }

    /**
     * 添加会场
     *
     * @param attendeeInfo 用户
     * @param callback     回调
     */
    public static void addSite(AttendeeInfo attendeeInfo, MeetingCallback callback) {
        LogUtil.info("A user has tried to addSite(name: " + attendeeInfo.getSiteName() + ")");
        meetingServiceController.confCtrlServiceController.addSite(attendeeInfo, callback);
    }

    /**
     * 删除会场
     *
     * @param siteName 会长名
     * @param userId   userId
     * @param callback 操作结果回调
     */
    public static void deleteAttendee(String siteName, int userId, MeetingCallback callback) {
        LogUtil.info(TAG + "deleteAttendee() userId:" + userId);
        if (meetingServiceController == null) {
            return;
        }
        LogUtil.info(TAG + "A user has deleted the site(name: " + siteName + ")");
        meetingServiceController.confCtrlServiceController.deleteSite(userId, callback);
    }

    /**
     * 呼叫会场
     *
     * @param siteName 会场名
     * @param userId   userId
     * @param callback 操作结果回调
     */
    public static void callAttendee(String siteName, int userId, MeetingCallback callback) {
        LogUtil.info(TAG + " callAttendee() userId:" + userId);
        if (meetingServiceController == null) {
            return;
        }
        LogUtil.info(TAG + " A user has called the site(name: " + siteName + ")");
        meetingServiceController.confCtrlServiceController.callSite(userId, callback);
    }

    /**
     * 获取本终端操作的其他终端信息
     *
     * @return true 是
     */
    public static TermCtrlSiteInfo getTermCtrlSiteInfo() {
        LogUtil.info(TAG + " getTermCtrlSiteInfo()");
        if (meetingServiceController == null) {
            return null;
        }
        return meetingServiceController.confCtrlServiceController.getCtrlSiteInfo();
    }

    /**
     * 挂断会场
     *
     * @param userId   userId
     * @param callback 操作结果回调
     */
    public static void hangUpAttendee(int userId, MeetingCallback callback) {
        LogUtil.info(TAG + " hangUpAttendee() userId:" + userId);
        if (meetingServiceController == null) {
            return;
        }
        LogUtil.info(TAG + " A user has hangup the site(userId: " + userId + ")");
        meetingServiceController.confCtrlServiceController.endSite(userId, callback);
    }

    /**
     * 观看会场
     *
     * @param userId   userId
     * @param callback 操作结果回调
     */
    public static void watchAttendee(int userId, MeetingCallback callback) {
        LogUtil.info(TAG + " watchAttendee() userId:" + userId);
        if (meetingServiceController == null) {
            return;
        }
        LogUtil.info(TAG + " A user has viewed the site(userId: " + userId + ")");
        meetingServiceController.confCtrlServiceController.watchSite(userId, callback);
    }

    /**
     * 观看多画面
     *
     * @param callback 回调
     */
    public static void watchMultiPic(MeetingCallback callback) {
        LogUtil.info(TAG + " watchMultiPic()");
        if (meetingServiceController == null) {
            return;
        }
        LogUtil.info(TAG + " A user has viewed the multipic site");
        meetingServiceController.confCtrlServiceController.watchMultiPic(callback);
    }

    /**
     * 主席操作与会者 全部闭音/取消全部闭音
     *
     * @param isMute   true 全部闭音 false 取消全部闭音 （控制mic）
     * @param callback 操作结果回调
     */
    public static int muteAllAttendee(boolean isMute, MeetingCallback callback) {
        int i = meetingServiceController.confCtrlServiceController.allSiteMicrophoneClose(isMute, callback);
        LogUtil.info("A user has set all the sites muted == " + isMute);
        return i;
    }

    /**
     * 主席闭音/取消静音 某个会场
     *
     * @param userId   userid
     * @param isQuiet  true 静音 false 取消静音 （控制扬声器）
     * @param callback 操作结果回调
     */
    public static int quietAttendee(int userId, boolean isQuiet, MeetingCallback callback) {
        int result = meetingServiceController.confCtrlServiceController.singleSiteMicrophoneClose(userId, isQuiet, callback);
        LogUtil.info("A user has closed/opened the speaker for the user == " + userId + " ,isQuiet== " + isQuiet);
        return result;
    }

    /**
     * 获取会议剩余时间
     *
     * @return 剩余时间
     */
    public static int getConfLeftTime() {
        LogUtil.debug(TAG + " getConfLeftTime");
        try {
            int leftTime = meetingServiceController.confCtrlServiceController.getConfCtrlInfo().getConfLeftTime();
            LogUtil.debug(TAG + " getConfLeftTime leftTime:" + leftTime);
            return leftTime;
        } catch (NullPointerException e) {
            LogUtil.error(TAG + " getConfLeftTime exception");
            return 0;
        }
    }

    /**
     * 延长会议
     *
     * @param time     延长时间 分钟
     * @param callback 操作结果回调
     */
    public static void postponeConference(int time, MeetingCallback callback) {
        LogUtil.info(TAG + " postponeConference() time:" + time);
        if (meetingServiceController == null) {
            return;
        }
        meetingServiceController.confCtrlServiceController.extendConference(time, callback);
    }

    /**
     * pip大小画面切换
     *
     * @param viewId viewId
     */
    public static void switchPipLocation(int viewId) {
        int result = meetingServiceController.flexibleLayoutController.switchPipLocation(viewId);
        LogUtil.info("switchPipLocation() viewId:" + viewId + " result = " + result);
    }

    /**
     * pip小画面位置切换
     */
    public static void movePipMode(LayoutMode mode) {
        int result = meetingServiceController.flexibleLayoutController.movePipMode(mode);
        LogUtil.info("move pip mode = " + mode + " result = " + result);
    }

    /**
     * 隐藏/显示PIP小画面
     */
    public static void hideView(int viewId, boolean isHidden) {
        int result = meetingServiceController.flexibleLayoutController.hideView(viewId, isHidden);
        LogUtil.info("Set pip view isHidden = " + isHidden + " result = " + result);
    }

    /**
     * 从home页返回视频画面
     * @param viewId
     */
    public static void backToVideoScreen(int viewId) {
        int result = meetingServiceController.flexibleLayoutController.backToVideoScreen(viewId);
        LogUtil.info("backToVideoScreen result = " + result);
    }

    /**
     * 共享中信息
     *
     * @return 共享中信息实体
     */
    public static ShareCurInfo getCurShareInfo() {
        return meetingServiceController.shareServiceController.getCurShareInfo();
    }

    /**
     * 开启免打扰
     */
    public static void startUndisturb() {
        int result = meetingServiceController.startUndisturb();
        LogUtil.info("Start undisturb result = " + result);
    }

    /**
     * 关闭免打扰
     */
    public static void stopUndisturb() {
        int result = meetingServiceController.stopUndisturb();
        LogUtil.info("Stop undisturb result = " + result);
    }

    /**
     * 查询是否开启免打扰
     */
    public static boolean isUndisturbState() {
        return meetingServiceController.getUndisturbedState() == 1;
    }

    /**
     * 设置布局模式
     *
     * @param layoutMode
     */
    public static void setLayoutMode(LayoutMode layoutMode) {
        int result = meetingServiceController.flexibleLayoutController.setDefaultLayoutMode(layoutMode);
        LogUtil.info("Set layout mode = " + layoutMode + " result = " + result);
    }

    /**
     * 开始显示本端视频画面
     *
     * @param localView 窗口信息
     * @return 0：成功  其他：错误码
     */
    public static int startLocalView(VideoLocalView localView) {
        int result = meetingServiceController.flexibleLayoutController.startLocalView(localView);
        LogUtil.info("startLocalView result = " + result);
        return result;
    }

    /**
     * 开始显示远端视频画面
     *
     * @param remoteViewList 远端视频画面信息列表
     * @return 0：成功  其他：错误码
     */
    public static int startRemoteView(List<VideoRemoteViewAndUser> remoteViewList) {
        int result = meetingServiceController.flexibleLayoutController.startRemoteView(remoteViewList);
        LogUtil.info("startRemoteView result = " + result);
        return result;
    }

    /**
     * 停止显示远端视频画面
     *
     * @param streamType 要停止的流类型
     * @return 0：成功  其他：错误码
     */
    public static int stopLocalView(StreamType streamType) {
        int result = meetingServiceController.flexibleLayoutController.stopLocalView(streamType.getVal());
        LogUtil.info("stopLocalView result = " + result);
        return result;
    }

    public static int stopRemoteView(int userId, StreamType streamType) {
        int result = meetingServiceController.flexibleLayoutController.stopRemoteView(userId, streamType.getVal());
        LogUtil.info("stopRemoteView result = " + result);
        return result;
    }

    /**
     * 查询会议参数
     *
     * @return 成功 ConfParam, 失败null
     */
    public static ConfParam getConferenceParam() {
        if (!isCallServiceControllerValid("getConferenceParam")) {
            return null;
        }
        return meetingServiceController.callServiceController.getConferenceParam();
    }

    /**
     * 确认音频转视频请求
     *
     * @param isAccept 接受拒绝
     * @return 成功 0, 失败 错误码信息
     */
    public static int addVideoResponse(boolean isAccept) {
        if (!isCallServiceControllerValid("addVideoResponse")) {
            return -1;
        }
        int ret = meetingServiceController.callServiceController.addVideoResponse(isAccept);
        LogUtil.info("addVideoResponse result = " + ret);
        return ret;
    }

    private static boolean isMeetingServiceControllerValid(String methodInfo) {
        if (meetingServiceController == null) {
            LogUtil.error(TAG + " " + methodInfo + " meetingServiceController is null");
            return false;
        }
        return true;
    }

    private static boolean isCallServiceControllerValid(String methodInfo) {
        if (!isMeetingServiceControllerValid(methodInfo)) {
            return false;
        }
        if (meetingServiceController.callServiceController == null) {
            LogUtil.error(TAG + " " + methodInfo + " callServiceController is null");
            return false;
        }
        return true;
    }

    /**
     * 查询设备的License是否支持入驻式会议
     * @return
     */
    public static boolean isSupportOnPremisesConf() {
        boolean isSupport = meetingServiceController.isSupportOnPremisesConf();
        LogUtil.info("isSupportOnPremisesConf = " + isSupport);
        return isSupport;
    }

    public static void getVersion() {
        String platVersion = meetingServiceController.getPlatformVersion();
        String sdkVersion = meetingServiceController.getSdkVersion();
        LogUtil.info("platVersion = " + platVersion);
        LogUtil.info("sdkVersion = " + sdkVersion);
    }
}
